import request from "@/api";
export const userListApi = (params: IUserListParams): RES<IUserListModel> =>
  request.get("/admin/list", { params });

export const switchUserStatusApi = (id: number, status: number) :RES<number>=>
  request.post(`/admin/updateStatus/${id}?status=${status}`);

export const addUserApi = (params: IUserModel): RES<IUserModel> => request.post('/admin/register', params)

export const getUserById = (id: number): RES<IUserModel> => request.get(`/admin/${id}`)

export const updateUser = (params: IUserModel): RES<Number> => request.post(`/admin/update/${params.id}`, params)

export const getRoleListApi=():RES<IRoleModel[]>=>request.get("/role/listAll")

export const getRolesByUserIdApi = (adminId: number): RES<IRoleModel[]> => request.get(`/admin/role/${adminId}`)

export const updateUserRolesApi = (id: number, ids: number[]): RES<number> => request.post(`/admin/role/update?adminId=${id}&roleIds=${ids.join(",")}`)


export const updateRoleAPI=(id:number,ids:number[]):RES<number>=>request.post(`/admin/role/update?adminId=${id}&roleIds=${ids}`)

export const RoleListAPI=(params:IUserListParams):RES<IRoleListModel>=>request.get(`/role/list`,{params})

export const switchRoleStatusAPI=(id: number, status: number): RES<number>=>request.post(`/role/updateStatus/${id}?status=${status}`)

export const editRoleAPI=(params:IRoleModel):RES<number>=>request.post(`/role/update/${params.id}`,params)

export const addRoleAPI = (params: IRoleModel): RES<IRoleModel> => request.post("/role/create", params)

export const getUserRoleAPI = (adminId: number): RES<IRoleModel[]> => request.get(`/admin/role/${adminId}`)

export const getRourceListByRoleIdApi = (roleId: number): RES<IResourceModel[]> => request.get(`/role/listResource/${roleId}`)

export const resourceListAllApi = (): RES<IResourceModel[]> => request.get("/resource/listAll")

export const resourceCategoryAllApi = (): RES<IResourceCategoryModel[]> => request.get("/resourceCategory/listAll")

export const allocResourceApi = (params: allocResourceParams):RES<{}> => request.post(`/role/allocResource?roleId=${params.roleId}&resourceIds=${params.resourceIds.join(",")}`) 

export const treeListApi = (): RES<ItreeMenu[]> => request.get('/menu/treeList')

export const getUserTree=(roleId:number):RES<IGetUserTree[]>=>request.get(`role/listMenu/${roleId}`)